package org.easytouseit.rabbitmq.topic.producer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * 生产者
 *
 * @author guojm
 * @version V1.0
 * @date 2018-12-28 下午 15:12
 */

/*@Component
public class TopicMsgProducer implements RabbitTemplate.ConfirmCallback{

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private RabbitTemplate rabbitTemplate;
    @Autowired
    public TopicMsgProducer(RabbitTemplate rabbitTemplate){
        this.rabbitTemplate=rabbitTemplate;
        this.rabbitTemplate.setConfirmCallback(this);
    }
    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        logger.info("Topic回调id:" + correlationData);
        if (ack) {
            logger.info("Topic消息成功消费");
        } else {
            logger.info("Topic消息消费失败:" + cause);
        }
    }

    public void sendMsg1(String content) {
        CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
        //把消息放入ROUTINGKEY_A对应的队列当中去，对应的是队列A
        rabbitTemplate.convertAndSend(TopicRabbitMQConfig.TOPIC_EXCHANGE_NAME, TopicRabbitMQConfig.TOPIC_ROUTING_ONE, content, correlationId);
    }
    public void sendMsg2(String content) {
        CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
        //把消息放入ROUTINGKEY_A对应的队列当中去，对应的是队列A
        rabbitTemplate.convertAndSend(TopicRabbitMQConfig.TOPIC_EXCHANGE_NAME, TopicRabbitMQConfig.TOPIC_ROUTING_TWO, content, correlationId);
    }

}*/
